package com.study.java8.char12;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Apple {
    private static long counter;
    private final long id = counter++;

    public long id() {
        return id;
    }
}

class Orange {
}

public class ApplesAndOrangesWithoutGenerics {
    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        ArrayList apples = new ArrayList();
        for (int i = 0; i < 3; i++)
            apples.add(new Apple());
        // No problem adding an Orange to apples:
        apples.add(new Orange());
        for (Object apple : apples) {
            //((Apple) apple).id();
            // Orange is detected only at run time
        }
        List list =new ArrayList();
        Collections.addAll(list, "1", "2", "3");
        list.forEach(item -> {
            System.out.println(item);
        });


    }
}
//Exception in thread "main" java.lang.ClassCastException: com.study.java8.char12.Orange cannot be cast to com.study.java8.char12.Apple
//    at com.study.java8.char12.ApplesAndOrangesWithoutGenerics.main(ApplesAndOrangesWithoutGenerics.java:26)
